package com.jiamao.goplay.ui.discover.vm;

import android.app.Application;
import android.os.Bundle;

import androidx.annotation.NonNull;

import com.jiamao.goplay.bean.SearchAddrs;
import com.jiamao.goplay.ui.discover.AddrDetailFragment;

import java.text.DecimalFormat;

import androidx.databinding.ObservableField;
import me.goldze.mvvmhabit.base.BaseViewModel;
import me.goldze.mvvmhabit.base.MultiItemViewModel;
import me.goldze.mvvmhabit.binding.command.BindingAction;
import me.goldze.mvvmhabit.binding.command.BindingCommand;
import me.goldze.mvvmhabit.utils.KLog;

public class SearchItemVM extends MultiItemViewModel {

    private DecimalFormat decimalFormat=new DecimalFormat(".00");
    public ObservableField<String> name = new ObservableField<>("");
    public ObservableField<String> addr = new ObservableField<>("");
    public ObservableField<String> gotoNum = new ObservableField<>("");
    public ObservableField<Float> rat = new ObservableField<Float>();
    private SearchAddrs addrs;
    public SearchItemVM(@NonNull BaseViewModel viewModel, SearchAddrs addrs) {
        super(viewModel);
        if (addrs!=null){
            this.addrs = addrs;
            name.set(addrs.getName());
            KLog.d("getRating: "+addrs.getRating());
          // Float.valueOf(addrs.getBizExt().getRating().floatValue())
            rat.set(addrs.getRating());

            // gotoNum.set("0人想去");
             addr.set(addrs.getDistance()+"km，"+addrs.getCategory()+"，"+addrs.getCity()+addrs.getArea()+addrs.getAddress());


        }
    }

    //条目的点击事件
    public BindingCommand itemClick = new BindingCommand(new BindingAction() {
        @Override
        public void call() {

            if (addrs==null){
                return;
            }
            Bundle bundle = new Bundle();
            bundle.putString("id",addrs.getPlaceId());
            viewModel.startContainerActivity(AddrDetailFragment.class.getCanonicalName(),bundle);

           // viewModel.startContainerActivity(AddrDetailFragment.class.getCanonicalName());
            //     ToastUtils.showShort("我是头布局");
        }
    });
}
